package thread.basic;

public class Demo06_SetDeamon {
    public static void main(String[] args) {
        //setDeamon() 设置一个守护线程，该线程不会单独执行，
        //当其他非守护线程都执行结束后，自动退出
        Thread t1 = new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < 2; i++) {
                    System.out.println(".............t1");
                }
            }
        };

        Thread t2 = new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < 50; i++) {
                    System.out.println("............t2");
                }
            }
        };

        t2.setDaemon(true);
        //当传入true就意味着设置为守护线程
        //t1挂掉的时候 t2在时间缓冲区结束后就会挂掉
        t1.start();
        t2.start();
    }
}
